
//搜索内容
var strHref =  document.location.toString()
console.log(strHref);
var index = strHref.indexOf('?')+1;
strHref = strHref.substring(index)
var arrAnd = strHref.split('&')
var obj = {}
for(let i = 0; i< arrAnd.length ; i++){
    let str1 = arrAnd[i].split('=')[0]
    let str2 = arrAnd[i].split('=')[1]
    obj[str1] = str2
}
function searchShop(){
    axios({
        url:'/home/searchShop/getAllLikeHome',
        method:'GET',
        params:{
            content:obj.content,
            setting:obj.setting
        }
    })
    .then(data =>{
        console.log(data);
        // let headInner = document.getElementsByClassName('headInner')[0]
        // headInner.innerHTML = ``
        // if(data.data.data[0].length === 0){
            
            
        //     headInner.innerHTML =`
        //         <div class="searchNone">
        //             <i class="iconfont sousuowujieguo1"></i>
        //             <p>没有找到您想要的结果~~~看看其他的吧</p>
        //         </div>
        //     `
        // }else{
            let shopUl = document.getElementsByClassName('shopUl')[0]
            console.log(shopUl);
            document.getElementsByClassName('sort')[0].innerHTML = decodeURIComponent(obj.setting)
            document.getElementsByClassName('sort')[1].innerHTML = '宝贝'
            document.getElementsByClassName('searchInput')[0].value = decodeURIComponent(obj.content)
            document.getElementsByClassName('shopCounts')[0].innerHTML = data.data.data[0].length
            // let shopProduct = document.getElementsByClassName('shopProduct')[0]
            // // 商品图片
            // shopProduct.innerHTML = ''
            
            // 查询出来的所有商品
            shopUl.innerHTML = ``
            for(let i =0 ; i<data.data.data[0].length; i++){
                shopUl.innerHTML += `
                    <li class="shopList">
                        <ul class="listUl">
                            <li class="liImg">
                                <a href="javascript:;">
                                    <img src="${data.data.data[0][i].cover}" alt="">
                                </a>
                            </li>
                            <li class="listInfo">
                                <h4>
                                    <a href="#">
                                        ${data.data.data[0][i].shopName}
                                    </a>
                                    </h4>
                                <p>
                                    卖家:
                                    <span class="shoperName">
                                        <a href="#">123456789</a> 
                                    </span>
                                </p>
                                <p>主营:
                                    <span>${data.data.data[0][i].introduction}</span>
                                </p>
                            </li>
                            <li class="shopProduct">
                                
                            </li>
                            <div style="clear: both;"></div>
                        </ul>
                    </li>
                `
                
                for(let j =0; j<data.data.data[0][i].goods.length; j++){
                    let imgObj = ''
                    imgObj += `
                                <div class="oneProduct">
                                    <div class="oneImg">
                                        <a href="#">
                                            <img src="${data.data.data[0][i].goods[j].cover}" alt="">
                                        </a>
                                    </div>
                                    <div class="onePrice">￥${data.data.data[0][i].goods[j].goodsPrice}</div>
                                </div>
                        `
                        if(j === data.data.data[0][i].goods.length-1){
                            imgObj += `
                            <div style="clear: both;"></div>
                            `
                        }
                        document.getElementsByClassName('shopProduct')[i].innerHTML += imgObj
                }
                
            }
        // }
        
    })
    .catch(err => {
        console.log(err);
    })
}
searchShop()